package com.kwd.news.controller;

import com.alibaba.fastjson.JSON;
import com.kwd.news.model.LmCmsPhone;
import com.kwd.news.po.Mobilehd;
import com.kwd.news.service.LmCmsMobileService;
import com.kwd.news.service.LmCmsPhoneService;
import com.kwd.news.utils.MobileUtil;
import com.meirengu.common.RedisClient;
import com.meirengu.common.StatusCode;
import com.meirengu.model.Result;
import com.meirengu.utils.NumberUtil;
import com.meirengu.utils.RequestUtil;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * ${DESCRIPTION}
 *
 * @author Mao
 * @create 2017-12-19 12:27
 */
@Controller
@RequestMapping("mobile")
public class MobileController extends BaseController {

    Logger logger = LoggerFactory.getLogger(MobileController.class);

    @Autowired
    private LmCmsPhoneService lmCmsPhoneService;

    @Autowired
    private LmCmsMobileService lmCmsMobileService;


    @RequestMapping(value = "/{mobile}", method = RequestMethod.GET)
    @ResponseBody
    public Result detail(@PathVariable("mobile") String mobile) {
        try {
            Result result = lmCmsPhoneService.getMobilehd(mobile);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(ExceptionUtils.getFullStackTrace(e));
            logger.error(">> MobileController.insert throw exception: {}", e);
            return super.setResult(StatusCode.INTERNAL_SERVER_ERROR, "", StatusCode.codeMsgMap.get(StatusCode.INTERNAL_SERVER_ERROR));
        }
    }


    @RequestMapping(value = "/city_exist", method = RequestMethod.GET)
    public void cityExist() {

        for (int i = 0; i <= 40; i++) {
            lmCmsPhoneService.cityExist(i * 10000, 10000 * (i + 1));
        }
    }

    @RequestMapping(value = "/check", method = RequestMethod.GET)
    public void check() {

        for (int i = 0; i <= 40; i++) {
            lmCmsPhoneService.check(i * 10000, 10000 * (i + 1));
        }
    }

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public void test() {
        lmCmsMobileService.warpJson();
    }

    @RequestMapping(value = "/save", method = RequestMethod.GET)
    @ResponseBody
    public Result saveToRedis() {
        return lmCmsMobileService.saveToRedis();
    }

    @RequestMapping(value = "/warpJson2", method = RequestMethod.GET)
    public void warpJson2() {
        lmCmsMobileService.warpJson2();
    }

    @RequestMapping(value = "/warpJson3", method = RequestMethod.GET)
    public void warpJson3() {
        lmCmsMobileService.warpJson3();
    }

    @RequestMapping(value = "/supercheck", method = RequestMethod.GET)
    public void supercheck() {
        for (int i = 0; i <= 40; i++) {
            lmCmsPhoneService.supercheck(i * 10000, 10000 * (i + 1));
        }
    }

    @RequestMapping(value = "/setRedis", method = RequestMethod.GET)
    public void setRedis() {
        lmCmsPhoneService.setRedis();
    }


}
